package com.cabd.test;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;

import com.csvreader.CsvReader;
import com.csvreader.CsvWriter;

public class WriteCSVFile {

	public static void main(String[] args) throws IOException {
		String pathWrite = "C:\\Users\\Hao\\Desktop\\flight_information_temp.csv";
		
		String pathRead = "C:\\Users\\Hao\\Desktop\\flight_information.csv";
		
		CsvWriter csvWriter = new CsvWriter(pathWrite, ',', Charset.forName("GBK"));
		
		CsvReader csvReader = new CsvReader(pathRead, ',', Charset.forName("GBK"));
		
		String []records = {"出发机场","到达机场","航班编号","计划起飞时间","计划到达时间","实际起飞时间","实际到达时间","飞机编号","航班是否取消","需验证标识（1为需提交结果、0不需要提交）"};
		csvWriter.writeRecord(records);
		
		csvReader.readHeaders();
		while(csvReader.readRecord()){
			String []arg = csvReader.getRawRecord().split(",");
			for(String eString:arg) {
				System.out.print(eString + "  ");
			}
			System.out.println();
			csvWriter.writeRecord(arg);
		}
		
		csvReader.close();
		csvWriter.close();
		
		File tempFile = new File(pathRead);
		tempFile.delete();
		
		File newFile = new File(pathWrite);
		newFile.renameTo(new File(pathRead));
	}
}
